import { loginAPI } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    reToken(state) {
      // 清除vue中的token
      state.token = ''
      // 调用方法清除cookie中的token
      removeToken()
    }
  },
  actions: {
    async loginToken(state, data) {
      console.log(data)
      // console.log(userDetail)
      const res = await loginAPI(data)
      state.commit('setToken', res.data.token)
      console.log(res)
    }
  }
}
